#region Microsoft Public License
/*
 * (c) Copyright Chenjun Wu. http://utablesdk.codeplex.com
 * 
 * This source is subject to the Microsoft Public License (Ms-PL).
 * Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details.
 * All other rights reserved.
 */
#endregion

﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.Specialized;
using System.Windows;
using System.Windows.Controls;

namespace UTable.Objects.Controls
{
    public class ObservablePanel: Panel
    {
        ObservableUIElementCollection _children;

        protected override UIElementCollection CreateUIElementCollection(FrameworkElement logicalParent)
        {
            if (_children != null)
                _children.CollectionChanged -= OnChildrenChanged;
            _children = new ObservableUIElementCollection(this, logicalParent);
            _children.CollectionChanged += OnChildrenChanged;
            return _children;
        }

        protected virtual void OnChildrenChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            if (ChildrenChanged != null)
                ChildrenChanged(sender, e);
        }

        public event NotifyCollectionChangedEventHandler ChildrenChanged;
    }
}
